package cn.stylefeng.guns.modular.User.controller;

import cn.stylefeng.guns.core.annotion.BusinessLog;
import cn.stylefeng.guns.core.enums.LogAnnotionOpTypeEnum;
import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.core.pojo.response.SuccessResponseData;
import cn.stylefeng.guns.modular.User.param.UserOrgParam;
import cn.stylefeng.guns.modular.User.service.UserOrgService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class UserOrgController {

    @Resource
    private UserOrgService userOrgService;


    @GetMapping("/org/list")
    @BusinessLog(title = "user_org_增加_查询所有", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData list(UserOrgParam userOrgParam){
        return new SuccessResponseData(userOrgService.list(userOrgParam));
    }

    @PostMapping("/org/add")
    @BusinessLog(title = "user_org_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData add(@RequestBody @Validated(UserOrgParam.add.class) UserOrgParam userWaiterParam) {
        userOrgService.add(userWaiterParam);
        return new SuccessResponseData();
    }

    @PostMapping("/org/delete")
    @BusinessLog(title = "user_org_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData delete(@RequestBody @Validated(UserOrgParam.delete.class) UserOrgParam userWaiterParam) {
        userOrgService.delete(userWaiterParam);
        return new SuccessResponseData();
    }

    @PostMapping("/org/edit")
    @BusinessLog(title = "user_org_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData edit(@RequestBody @Validated(UserOrgParam.edit.class) UserOrgParam userWaiterParam) {
        userOrgService.edit(userWaiterParam);
        return new SuccessResponseData();
    }


    @PostMapping("/org/changeStatus")
    @BusinessLog(title = "user_org_修改状态", opType = LogAnnotionOpTypeEnum.CHANGE_STATUS)
    public ResponseData changeStatus(@RequestBody @Validated(UserOrgParam.changeStatus.class) UserOrgParam userWaiterParam) {
        userOrgService.changeStatus(userWaiterParam);
        return new SuccessResponseData();
    }
}
